module axis_wrapper #(
  parameter SIZE = 8,
  parameter DATA_WIDTH = 64
)(
  input  wire                     aclk,
  input  wire                     aresetn,
  
  // AXI Stream输入接口
  input  wire [DATA_WIDTH-1:0]    s_axis_a_tdata,
  input  wire                     s_axis_a_tvalid,
  output wire                     s_axis_a_tready,
  
  input  wire [DATA_WIDTH-1:0]    s_axis_b_tdata,
  input  wire                     s_axis_b_tvalid,
  output wire                     s_axis_b_tready,
  
  // AXI Stream输出接口
  output wire [127:0]             m_axis_res_tdata,
  output wire                     m_axis_res_tvalid,
  input  wire                     m_axis_res_tready
);

  // 双缓冲设计
  reg [DATA_WIDTH-1:0] a_buffer[0:1];
  reg [DATA_WIDTH-1:0] b_buffer[0:1];
  reg buffer_sel = 0;
  
  always @(posedge aclk) begin
    if (!aresetn) begin
      buffer_sel <= 0;
    end else if (s_axis_a_tvalid && s_axis_b_tvalid) {
      a_buffer[buffer_sel] <= s_axis_a_tdata;
      b_buffer[buffer_sel] <= s_axis_b_tdata;
      buffer_sel <= ~buffer_sel;
    }
  end
  
  // 矩阵计算触发逻辑
  wire calc_start = (buffer_sel == 1);
  matrix_mult #(.SIZE(SIZE)) core (
    .clk(aclk),
    .rst_n(aresetn),
    .a_matrix(a_buffer[0]),
    .b_matrix(b_buffer[0]),
    .result(result)
  );
  
  // 结果打包输出
  res_packer u_packer (
    .clk(aclk),
    .result(result),
    .m_axis_tdata(m_axis_res_tdata),
    .m_axis_tvalid(m_axis_res_tvalid)
  );
endmodule